package com.cool4j.generator.util;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;

/**
 * 属性文件操作工具类
 *
 * @author Frank create on 16/1/8 19:06
 */
public class PropUtil {

    public synchronized static String getPropertyFromFile(String fileName, String key) {
        String filePath =  System.getProperty("user.dir") + "\\" + fileName;

        InputStream input;
        ResourceBundle resourceBundle;
        String result = "";
        try {
            input = new BufferedInputStream(new FileInputStream(filePath));
            resourceBundle = new PropertyResourceBundle(input);
            result = resourceBundle.getString(key).trim();
        } catch (IOException | NullPointerException e) {
            e.printStackTrace();
        }

        return result;
    }

}
